Creates a new subindex and attaches it to its parent's Subindexes collection.
Namespace:
C1.LiveLinq.IndexingAssembly: C1.LiveLinq (in C1.LiveLinq.dll)
Syntax
C# |
---|
public Subindex<T, TKey> Add<TKey>( Expression<Func<T, TKey>> keySelector, bool keyIsUnique, bool onlyOnce ) |
Visual Basic |
---|
Public Function Add(Of TKey) ( _ keySelector As Expression(Of Func(Of T, TKey)), _ keyIsUnique As Boolean, _ onlyOnce As Boolean _ ) As Subindex(Of T, TKey) |
Parameters
- keySelector
- Type: System.Linq.Expressions..::..Expression<(Of <(<'Func<(Of <(<'T, TKey>)>)>>)>)>
Key selector expression of the subindex, see KeySelector.
- keyIsUnique
- Type: System..::..Boolean
Specifies whether the key used in this subindex is unique for any given value of the parent key (default: false).
- onlyOnce
- Type: System..::..Boolean
Specifies whether it is required that the subindex does not exist prior to this method call (default: false). If a subindex with this keySelector already exists, an exception is thrown if it is true, and this method call is ignored if it is false.
Type Parameters
- TKey
- The type of the subindex key.
Return Value
The new subindex added to its parent's Subindexes collection.Remarks
A unique index occupies less memory and performs better than a non-unique index (although the difference isn't dramatic). Therefore, for unique keys, it's recommended to specify the corresponding index as unique.
But do that only if you are sure that the key is indeed unique, as it imposes a uniqueness constraint on the indexed collection. An attempt to modify the indexed collection violating the uniqueness throws an InvalidOperationException.
For a subindex, uniqueness means that any given pair of parent key and subindex key values uniquely determines an item in the indexed collection.